package com.example.yls.demoa;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
          private ImageView img;
          private Button btn;
          private int[] arr={
                  R.drawable.dog1,
                  R.drawable.dog2,
                  R.drawable.dog3,
                  R.drawable.dog4,
                  R.drawable.dog5};
          int index=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img=findViewById(R.id.img_dog);
        btn=findViewById(R.id.btn_next);

           btn.setOnClickListener(new View.OnClickListener() {


               @Override
               public void onClick(View view) {
                index=(index+1)%arr.length;
                img.setImageResource(arr[index]);


               }
           });


    }
}
